import { RankBaseItem } from "./RankBaseItem";
import { GTextFormat } from "../../../common/GTextFormat";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { TToplist } from "../../../../Message/Db/Tables/TToplist";
import { SEntityId } from "../../../../Message/Public/SEntityId";
import { ColorConfig } from "../../resource/ColorConfig";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { EToplistType } from "../../../../Message/Public/EToplistType";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
type int = number;
//class GuildRankItem
    
    export  class GuildRankItem extends RankBaseItem
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._tf = new GTextFormat("", 12, 11661311, false, false, false, null, null, flash.text.TextFormatAlign.CENTER);
            this._rankTxt = this.createTextField("", 0, 0, 25, 33, this._tf);
            this._nameTxt = this.createTextField("", 25, 0, 150, 33, this._tf);
            this._campTxt = this.createTextField("", 135, 0, 90, 33, this._tf);
            this._valueTxt = this.createTextField("", 175, 0, 160, 33, this._tf);
            this._attributeTxt = this.createTextField("", 270, 0, 130, 33, this._tf);
            this._rangeTxt = this.createTextField("", 375, 0, 120, 33, this._tf);
            this._bitmap = new Object /* flash.display.Bitmap */();
            var loc1=ObjCreate.createBg(0, 25, 460, 2, this, ImagesConst.SplitLine);
            return;
        }

        /* internal  */createTextField(arg1: string, arg2: int, arg3: int, arg4: int, arg5: int, arg6: Object /* flash.text.TextFormat */): Object /* flash.text.TextField */
        {
            var loc1;
            (loc1 = new Object /* flash.text.TextField */()).x = arg2;
            loc1.y = arg3;
            loc1.width = arg4;
            loc1.height = arg5;
            loc1.selectable = false;
            loc1.defaultTextFormat = arg6;
            loc1.text = arg1;
            addChild(loc1);
            return loc1;
        }

        public updateItem(arg1: TToplist, arg2: int): void
        {
            var loc5=null;
            if (arg1 == null) 
            {
                this._rankTxt.text = "";
                this._nameTxt.text = "";
                this._campTxt.text = "";
                this._valueTxt.text = "";
                this._attributeTxt.text = "";
                this._rangeTxt.text = "";
                _sEntityId = null;
                _data = null;
                if (this._bitmap.parent) 
                {
                    removeChild(this._bitmap);
                }
                clearBgColor();
                return;
            }
            _data = arg1;
            _sEntityId = new SEntityId();
            _sEntityId.type = 1;
            _sEntityId.id = arg1.ownerId;
            _sEntityId.typeEx = _serverId;
            this._rank = arg1.rank;
            var loc1=arg1.lastRank;
            this._rankTxt.text = this._rank.toString();
            var loc2=ColorConfig.instance.getCountryColor(arg1.propertyOne).intColor;
            this._nameTxt.htmlText = "<a href=\'event: 0\'><u>" + arg1.entityName + "</u></a>";
            this._nameTxt.addEventListener(flash.events.TextEvent.LINK, this.onNameTxtLinkHandler);
            this._nameTxt.textColor = loc2;
            var loc3=arg1.propertyOne;
            this._campTxt.text = GameDefConfig.instance.getECamp(loc3);
            var loc4=new GTextFormat("", 12, loc2, false, false, false, null, null, flash.text.TextFormatAlign.CENTER);
            if (arg2 != EToplistType._EToplistTypeGuildLevel) 
            {
                if (arg2 == EToplistType._EToplistTypeGuildAsset) 
                {
                    this._valueTxt.text = arg1.valueTwo.toString();
                }
            }
            else 
            {
                this._valueTxt.text = arg1.valueThree.toString();
            }
            this._attributeTxt.text = arg1.valueOne.toString();
            var loc6=true;
            if (this._bitmap.parent) 
            {
                removeChild(this._bitmap);
            }
            if (loc1 != 0) 
            {
                if (this._rank > loc1) 
                {
                    this._bitmap = GlobalClass.getBitmap(ImagesConst.RangeDecline);
                    loc5 = (this._rank - loc1).toString();
                }
                else if (this._rank < loc1) 
                {
                    this._bitmap = GlobalClass.getBitmap(ImagesConst.RangeRaise);
                    loc5 = (loc1 - this._rank).toString();
                }
                else if (this._rank == loc1) 
                {
                    this._bitmap = GlobalClass.getBitmap(ImagesConst.RangeSame);
                    loc5 = "";
                }
            }
            else 
            {
                loc6 = false;
                loc5 = Language.getString(32078);
            }
            if (loc6) 
            {
                this._bitmap.x = 418;
                this._bitmap.y = 2;
                addChild(this._bitmap);
            }
            this._rangeTxt.text = loc5;
            return;
        }

        /* internal  */onNameTxtLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (_data) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildInfoWindowOpen, _data.entityId));
            }
            return;
        }

        /* internal */ /* var */_tf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_rankTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_campTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_valueTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_attributeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_rangeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_bitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_rank: int;
    }
